from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.common.alert import Alert

class ContactsPage(BasePage):
    """合同页面做的操作"""
    click_add_contract_locator=(By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
    click_look_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(10) > a:nth-child(1)')
    click_edit_contract_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(10) > a:nth-child(2)')
    noselect_del_locator = (By.CSS_SELECTOR, '#delete')
    del_tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-error')
    select_contract_del_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    del_successful_contract_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')

    def click_add_contract(self):
        """点击添加合同"""
        self.driver.find_element(*self.click_add_contract_locator).click()

    def click_contract_look(self):
        """点击查看"""
        self.driver.find_element(*self.click_look_locator).click()
    def click_edit_contract(self):
        """点击编辑合同"""
        self.driver.find_element(*self.click_edit_contract_locator).click()


    def click_del_btn(self):
        """ 不勾选合同进行删除,出现弹窗，点击确定"""
        self.driver.find_element(*self.noselect_del_locator).click()
        alert = Alert(self.driver)
        self.driver.switch_to.alert.accept()

    def del_tips(self):
        """断言,没有删除"""
        del_tips=self.driver.find_element(*self.del_tips_locator).text
        return del_tips

    def select_one_del(self):
        """勾选单个合同进行删除"""
        self.driver.find_element(*self.select_contract_del_locator).click()

    def click_del(self):
        """进行删除,# 弹出弹窗，点击确定"""
        self.driver.find_element(*self.noselect_del_locator).click()
        self.driver.switch_to.alert.accept()

    def del_successful_tips_contract(self):
        """断言删除成功"""
        del_successful_tips=self.driver.find_element(*self.del_successful_contract_locator).text
        return del_successful_tips


